package space.sakana.edusysback.controller;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import space.sakana.edusysback.result.Result;
import space.sakana.edusysback.service.PaperService;

@RestController
@RequestMapping("/api/paper")
public class PaperController {

    private PaperService paperService;

    @Autowired
    public void autowiredService(PaperService paperService){
        this.paperService = paperService;
    }

    /**
     * 获取paper
     * @param pid paper id
     */
    @RequestMapping("/{pid}")
    public Result getPaper(@PathVariable int pid, HttpServletRequest request, HttpServletResponse response){
        return paperService.getPaper(pid, request, response);
    }

    @RequestMapping("/delete/{pid}")
    public Result deletePaper(@PathVariable int pid, HttpServletRequest request, HttpServletResponse response){
        return paperService.deletePaper(pid, request, response);
    }

    @RequestMapping("/all")
    public Result getAllPaper(HttpServletRequest request, HttpServletResponse response){
        return paperService.getAllPaper(request, response);
    }

    /**
     * 添加paper
     * @param data paper json
     */
    @RequestMapping("/add")
    public Result addPaper(@RequestParam String data, HttpServletRequest request, HttpServletResponse response){
        return paperService.addPaper(data, request, response);
    }

    /**
     * 修改paper
     * @param data paper json
     */
    @RequestMapping("/update")
    public Result updatePaper(@RequestParam String data, HttpServletRequest request, HttpServletResponse response){
        return paperService.updatePaper(data, request, response);
    }

    /**
     * 获取paper items
     * @param pid paper id
     */
    @RequestMapping("/item/{pid}")
    public Result getPaperItems(@PathVariable int pid, HttpServletRequest request, HttpServletResponse response){
       return paperService.getPaperItems(pid, request, response);
    }

    /**
     * 向paper内添加item
     * @param pid paper id
     * @param data paper item json
     */
    @RequestMapping("/item/add/{pid}")
    public Result addPaperItem(@PathVariable int pid, @RequestParam String data, HttpServletRequest request, HttpServletResponse response){
        return paperService.addPaperItem(pid, data, request, response);
    }

    /**
     * 修改paper内的item
     * @param pid paper id
     * @param data paper item json
     */
    @RequestMapping("/item/update/{pid}")
    public Result updatePaperItem(@PathVariable int pid, @RequestParam String data, HttpServletRequest request, HttpServletResponse response){
        return paperService.updatePaperItem(pid, data, request, response);
    }

    @RequestMapping("/jobtarget/{id}")
    public Result getPaperItemByJobTarget(@PathVariable int id, HttpServletRequest request, HttpServletResponse response){
        return paperService.getPaperItemByJobTarget(id, request, response);
    }

}
